{% extends "base.html" %}
{% block title %}学生信息管理系统{% endblock %}

{% block page_content %}
<div class="container">
    <div class="page-header">
        <h1>学生信息列表</h1>
        <div>
            <a href="{{ url_for('main.index') }}" class="btn btn-primary btn-xs">所有学生</a>
            {% for m in majors %}
            <a href="{{ url_for('main.filter_by_major', major_id=m.id) }}" class="btn btn-default btn-xs">{{ m.major_name }}</a>
            {% endfor %}
        </div>
    </div>
    {% if current_user.is_authenticated and current_user.role == 'admin' %}
    <a class="btn btn-default" href="{{ url_for('main.new_stud') }}">添加学生</a>
    {% endif %}
    <h4>当前共有{{ studs|length }}名学生</h4>
    <div class="mt-3">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>出生日期</th>
                    <th>性别</th>
                    <th>专业</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
        {%for stud in studs%}
        <tr>
            <td>{{ stud.id }}</td>
            <td>{{ stud.studentName }}</td>
            <td>{{ stud.studentBirth }}</td>
            <td>
                {%if stud.isMale%}
                    男
                {%else%}
                    女
                {%endif%}
            </td>
            <td>
                {%if stud.major%}
                    <span class="label label-info">{{ stud.major.major_name }}</span>
                {%else%}    
                    <span class="label label-default">未分配专业</span>
                {%endif%}
            </td>
            <td>
                {% if current_user.is_authenticated and current_user.role == 'admin' %}
                <a class="btn btn-default" href="{{ url_for('main.edit_stud',id=stud.id) }}">编辑</a >
                <a class="btn btn-default" href="{{ url_for('main.del_stud',id=stud.id) }}">删除</a >    
                {% endif %}
            </td>   
        {%else%}
        <p class="text-muted">暂无学生信息</p>
        {%endfor%}
    </div>
</div>
{%endblock%}